﻿using System;
using System.Collections.Generic;

namespace WholeSlideImageViewer
{
    internal class AssociatedImageDialogViewModel : ViewModelBase
    {
        private readonly string _urlBase;
        private readonly string _id;
        private readonly IEnumerable<string> _names;

        private string? _selectedName;
        private string? _imageSource;

        public IEnumerable<string> Names => _names;

        public string? SelectedName
        {
            get => _selectedName;
            set
            {
                OnPropertyChanged(nameof(SelectedName), ref _selectedName, value);
                UpdateImageSource();
            }
        }

        public string? ImageSource { get => _imageSource; set => OnPropertyChanged(nameof(ImageSource), ref _imageSource, value); }

        private void UpdateImageSource()
        {
            ImageSource = !string.IsNullOrEmpty(_selectedName) ? _urlBase + "associated/" + _id + "/" + _selectedName + ".jpg" : null;
        }


        [Obsolete("Only use this constructor in design time.", true)]
        public AssociatedImageDialogViewModel()
        {
            _urlBase = string.Empty;
            _id = string.Empty;
            _names = Array.Empty<string>();
        }


        public AssociatedImageDialogViewModel(string urlBase, string id, IEnumerable<string> names)
        {
            _urlBase = urlBase;
            _id = id;
            _names = names;
        }
    }
}
